package com.breakfast.fun;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import android.support.multidex.MultiDex;

import com.fm.openinstall.OpenInstall;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Tracker;

import cn.jpush.android.api.JPushInterface;


/**
 * 全局Application类，用于某些全局变量的初始化及获取上下文环境
 * <p>
 * 每次更新正式版本时，需要：
 * 1.将日志工具类中的的调试开关关闭--------- L.java
 * 2.将谷歌分析中的自动捕获异常打开--------- analytics.xml
 * 3.连接到正式服务器地址        ---------- Api.java
 * 4.更新版本号和版本代码        ---------- AndroidManifest.xml,build.gradle
 * 5.更换服务器版本（html,nginx,后台）
 * Created by hp on 2016/8/13.
 */
public class App extends Application {

    private static App app;
    private Tracker mTracker;

    @Override

    public void onCreate() {
        super.onCreate();
        app = this;
        //设置谷歌统计发送行为报告时常间隔为15秒
        GoogleAnalytics.getInstance(this).setLocalDispatchPeriod(15);
        //初始化极光推送
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        OpenInstall.init(this, "sqd7v0");
//        OpenInstall.init(this);
        OpenInstall.setDebug(true);

    }


    public static Context getAppContext() {
        return app;
    }

    public static Resources getAppResources() {
        return app.getResources();
    }

    public static App getApp() {
        return app;
    }

    /**
     * Gets the default {@link Tracker} for this {@link Application}.
     *
     * @return tracker
     */
    synchronized public Tracker getDefaultTracker() {
        if (mTracker == null) {
            GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
            // To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
            //配置谷歌统计跟踪器
            mTracker = analytics.newTracker(R.xml.analytics);
        }
        return mTracker;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}